﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;

namespace AFT2
{
    [Serializable]
    public class BookMarksDataObject
    {   

        public BookMarksDataObject(string id, string title, string url, string visits, string date, string createdDate, string bookmark, string userEntered)
        {
            ID = id;
            Title = title;
            Url = url;
            Visits = visits;            
            Date = date;
            CreatedDate = createdDate;
            BookMark = bookmark;
            UserEntered = userEntered;
        }
        public string ID { get; set; }
        public string Title { get; set; }
        public string Url { get; set; }
        public string Visits { get; set; }
        public string Date { get; set; }
        public string CreatedDate { get; set; }
        public string BookMark { get; set; }
        public string UserEntered { get; set; }//직접 타이핑해서 들어간 북마크
    }

    [Serializable]
    public class BookMarksDataList
    {
        public BookMarksDataList()
        {
            this.data = new List<BookMarksDataObject>();

            /*
         private static final String CREATE_BOOKMARKS_TABLE = "create table bookmarks("
			+ "_id integer primary key autoincrement,"
			+ "b_id text,"
			+ "title text,"
			+ "url text,"
			+ "visits text,"
			+ "date text,"
			+ "created_date text,"						
			+ "bookmark text,"			
			+ "user_entered text)";
         */

            SQLiteConnection myConnection = new SQLiteConnection();
            myConnection.ConnectionString = "Data Source=db\\phoneData.db";
            myConnection.Open();
            SQLiteCommand sqlcmd = new SQLiteCommand(myConnection);
            sqlcmd.CommandText = "select * from bookmarks;";// table name 
            SQLiteDataReader reader = sqlcmd.ExecuteReader();
            while (reader.Read())
            {
                this.data.Add(
                    new BookMarksDataObject(
                        "" + reader["b_id"],
                        "" + reader["title"],
                        "" + reader["url"],
                        "" + reader["visits"],
                        "" + reader["date"],
                        "" + reader["created_date"],
                        "" + reader["bookmark"],
                        "" + reader["user_entered"])
                    );
            }

            reader.Close();
            myConnection.Close();
        }

        public List<BookMarksDataObject> data;
    }
}
